package homework12月8号.homework1.h5;

import java.lang.reflect.Constructor;

/*4.	有参构造+调用方法
使用反射创建Student对象，并用反射的方式调用show方法

public class Student {
    private String name;
private int age;

    public String show() {
        return "Student{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }
    public Student(String name, int age) {
        this.name = name;
        this.age = age;
    }
}
*/
public class Demo1 {
    public static void main(String[] args) throws Exception {
        Class<?> aClass = Class.forName("czxy.homework.h5.Student");
        Constructor<?> c = aClass.getDeclaredConstructor(String.class, int.class);
        Object xiaoa = c.newInstance("xiaoa", 18);
        Student st=(Student)xiaoa;
        String show = st.show();
        System.out.println(show);
    }
}
